//1.JS的对象

const person = {
    fisrtName : 'Cai',
    lastName : 'XuKun',
    age : 90,
    hobbies : ["Singing","Dancing","Rap","Playing basketball"],
    address :{
        street : "2.5 main St",
        city : "New York",
        state : "Florida"
    },


};

// const {fisrtName,lastName} = person;
// console.log(fisrtName,lastName);

const{
    lastName,
    age,
    hobbies,
    address : { street },
} = person;

// console.log(person.fisrtName,person.lastName);

console.log(street);

person.email = "example@example.com";

console.log(person.email);


//2.JS的对象数组

const todos = [
    {
        id : 1,
        text : "Get up",
        isComplete : true, 
    },

    {
        id : 2,
        text : "Brush teeth",
        isComplete : true, 
    },

    {
        id : 3,
        text : "Eat Breakfast",
        isComplete : true, 
    }

]

console.log(todos[1].text);

//转换为JSON格式

const todoJSON = JSON.stringify(todos);
console.log(todoJSON);

//3.JS中的if判断
const x = 11;
const y = 5;


if (x > 10 && y < 10){
    console.log("X > 10,Y <10");
}
// else if (x < 10) {
//     console.log("X小于10");
// }
// else {
//     console.log("X不是10");
// };





//三目运算符
const x1 = 100;

const color = x1 > 10 ? "Red" : "Blue"; 

console.log(color);

//switch语句
switch (color) {
    case "Red" :
        console.log("Color is Red");
        break;
    case "Blue":
        console.log("Color is Blue");
        break;
    default:
        console.log("Color is not red or blue");
        break;
}

//for循环
for(let i = 0; i < 10 ;i++){
    console.log(`For loop number:${i}`);
}


//while循环
let i = 0;
while(i < 10){
    console.log(`While loop number:${i}`);
    i ++;
}

for(let i = 0; i < todos.length ;i++){
    console.log(todos[i].text)  ;
}

for(let todo of todos){
    console.log(todo.text);
}




